/*
* @Description:登录
* @Author: lil
* @Date: 2021/11/19
**/
<template>
  <div class="login">
    <div class="login-hd">
      <img src="~@/assets/image/blockchain-login-title.png" alt="">
    </div>
    <div class="login-bd clearfix">
      <div class="login-bd-fl fl">
        <div>Hello~</div>
        <p>欢迎来到区块链平台</p>
      </div>
      <div class="login-bd-fr fr">
        <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form">
          <h3 class="title">登录</h3>
          <el-form-item prop="username" label="用户名">
            <el-input v-model="loginForm.username" type="text" auto-complete="off">
            </el-input>
          </el-form-item>
          <el-form-item prop="password" label="密码">
            <el-input v-model="loginForm.password" @paste.native.capture.prevent="handlePaste" type="password" auto-complete="off" oncut="return false"
                      @keyup.enter.native="handleLogin">
            </el-input>
          </el-form-item>
          <el-form-item style="width: 100%;margin-top:65px">
            <el-button :loading="loading" size="medium" type="primary" style="width: 100%"
                       @click.native.prevent="handleLogin">
              <span v-if="!loading">登 录<i class="el-icon-right"></i></span>
              <span v-else>登 录 中...</span>
            </el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
    <div class="el-login-footer">
      <span>Copyright © 2020 zhuofansoft.com All Rights Reserved.</span>
    </div>
  </div>
</template>

<script>
  export default {
    name: "Login",
    data() {
      return {
        title: this.Common.title,
        codeUrl: "",
        cookiePassword: "",
        loginForm: {
          username: "",
          password: "",
          captcha: "",
          uuid: "",
          publicKey: "",
        },
        loginRules: {
          username: [{
            required: true,
            trigger: "blur",
            message: "用户名不能为空",
          }, ],
          password: [{
            required: true,
            trigger: "blur",
            message: "密码不能为空",
          }, ],
          captcha: [{
            required: true,
            trigger: "change",
            message: "验证码不能为空",
          }, ],
        },
        loading: false,
        userData: [],
        authLogin: false
      };
    },
    methods: {
      handlePaste(){
      },
      handleLogin() {
        this.$refs.loginForm.validate((valid) => {
          if (valid) {
            // this.userData.forEach(item => {
            //   if (item.username == this.loginForm.username && item.password == this.loginForm.password) {
            //     this.authLogin = true;
            //   }
            // })
            // if (this.authLogin) {
            //   this.loading = true;
            //   this.$router.push({
            //     path: "/",
            //   });
            // } else {
            //   this.$message.error('用户名或密码错误！')
            // }

         

         

            this.$store
              .dispatch("Login", this.loginForm)
              .then(() => {
                this.$message.success('登录成功!')
                this.$router.push({
                  path: this.redirect || "/",
                });
             
              })
              .catch(() => {
               this.$message.error('登录失败!')
               this.loading = false;
              });
          }
        });
      },
    },
  };

</script>

<style lang="scss" scoped>
  .login {
    height: 100%;
    background-image: url("~@/assets/image/login-background.png");
    background-size: cover;
    overflow: hidden;

    .login-hd {
      margin: 40px 0 0 75px;
    }

    .login-bd {
      width: 1287px;
      margin: 0 auto;

      .login-bd-fl {
        color: #c5edff;
        margin-top: 400px;

        div {
          font-size: 42px;
          font-weight: bold;
        }

        p {
          font-size: 20px;
          margin-left: 200px;
          margin-top: 35px;

          &::before {
            content: '';
            width: 108px;
            height: 2px;
            background-color: rgba(197, 237, 255, .6);
            display: inline-block;
            vertical-align: middle;
            margin-right: 15px;
          }
        }
      }

      .login-bd-fr {
        margin-top: 90px;
      }
    }
  }

  .title {
    margin: 0px auto 30px auto;
    text-align: center;
    color: #007fff;
    font-size: 30px;
    font-weight: bold;
  }

  .login-form {
    border-radius: 6px;
    width: 470px;
    padding: 25px 25px 5px 25px;

    .el-form-item {
      margin-bottom: 35px;
    }

    &>>>.el-form-item__label {
      color: rgba(159, 197, 255, .4);
      font-size: 16px;

      &::before {
        display: none;
      }
    }

    .el-input {
      height: 50px !important;

      &>>>.el-input__inner {
        background-color: #021121 !important;
        border-color: #71d2ff;
        height: 50px !important;

      }
    }

    .el-button {
      height: 50px;
      font-size: 18px;
      background-image: linear-gradient(to right, #0096ff, #0072ff) !important;

      .el-icon-right {
        margin-left: 5px;
        font-size: 20px;
        vertical-align: text-bottom;
      }
    }

    .input-icon {
      height: 32px;
      width: 14px;
      margin-left: 2px;
    }

    .el-checkbox {
      &>>>.el-checkbox__inner {
        width: 18px;
        height: 18px;
        background-color: #021121;
        border-color: #71d2ff;

        &::after {
          transform: none;
          border: none;
        }
      }

      &.is-checked {
        &>>>.el-checkbox__inner::after {
          content: '';
          width: 20px;
          height: 19px;
          display: inline-block;
          border: none;
          transform: none;
          left: 0;
          top: -3px;
          background: url('~@/assets/image/checked-icon.png');
        }
      }

      &>>>.el-checkbox__label {
        font-size: 14px;
        color: rgba(159, 197, 255, .4);
      }
    }

  }

  .login-tip {
    font-size: 13px;
    text-align: center;
    color: #bfbfbf;
  }

  .login-code {
    width: 33%;
    height: 38px;
    float: right;

    img {
      width: 100%;
      height: 100%;
      cursor: pointer;
      vertical-align: middle;
    }
  }

  .el-login-footer {
    height: 42px;
    line-height: 42px;
    position: fixed;
    bottom: 0;
    width: 100%;
    text-align: center;
    color: rgba(159, 197, 255, .14);
    font-size: 12px;
    letter-spacing: 1px;
    background-color: rgba(6, 148, 255, .07);
  }

</style>
